package com.lanmao.emc.dao;

import com.lanmao.emc.enums.DBType;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.EnumMap;
import java.util.Map;

/**
 * 描述：
 *
 * @author lanmao
 * @since 2024年11月11日 20:39
 */
@Component
public class UpgradeDaoFactory {
    @Value("${es.upgrade.db-type:elasticsearch}")
    private String dbType;
    protected static final Map<DBType, UpgradeDao> DB_MAP = new EnumMap<>(DBType.class);

    public UpgradeDao getDao() {
        UpgradeDao upgradeDao = DB_MAP.get(DBType.getByValue(dbType.toLowerCase()));
        if (upgradeDao == null) {
            throw new RuntimeException("不支持的数据库类型:" + dbType);
        }
        return upgradeDao;
    }
}